<?php
class common_media_display {
	
	private $_md5 = null;
	private $_ext = '';
	private $_noMedia = false;
	private $_http = null;
	private $_default = null;
	public function __construct($row, $http = '', $default = null) {
		$this->_http = $http;
		$this->_default = $default;
		if(!$row->getMd5()) {
			$this->_noMedia = true;
		} else {
			$this->_md5 = common_media_config::md5Path($row->getMd5());
			$this->_ext = $row->getExtension() ? '.' . $row->getExtension() : '';
		}
	}
		
	public function __call($method, array $args) {
		if(preg_match('/^get(\w+?)$/', $method, $matches)) {
			return $this->get($matches[1]);
		}
		return null;
	}
	
	public function __toString() {
		return $this->get('original');
	}
	
	public function get($name) {
		$name = strtolower($name);
		if($this->_noMedia) {
			return $this->_default;
		} else {
			return $this->_http . $this->_md5 . '/' . $name . $this->_ext;
		}
	}
	
}

